package com.example.startup.manager

import android.os.Handler
import android.os.Looper
import java.util.concurrent.Executor
import java.util.concurrent.Executors
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import kotlin.math.max

/**
 * 线程并发处理
 */
object ExecutorManager {

    val CPU_COUNT = Runtime.getRuntime().availableProcessors()
    val CORE_POOL_SIZE = max(2, CPU_COUNT - 1)
    val MAXIMUM_POOL_SIZE = CORE_POOL_SIZE
    val KEEP_ALIVE_TIME = 5L

    public val cpuExecutor =
        ThreadPoolExecutor(
            CORE_POOL_SIZE,
            MAXIMUM_POOL_SIZE,
            KEEP_ALIVE_TIME,
            TimeUnit.SECONDS,
            LinkedBlockingQueue(),
            Executors.defaultThreadFactory()
        )

    val ioExecutor =
        Executors.newCachedThreadPool()
    val mainExecutor = Executor{
        Handler(Looper.getMainLooper()).post(it)
    }



}